//
//  HMMainViewController.swift
//  WeiBo
//
//  Created by 李立达 on 15/12/5.
//  Copyright © 2015年 heima11. All rights reserved.
//

import UIKit
import SVProgressHUD
class HMMainViewController: UITabBarController {

    
    lazy var coverView :UIImageView = {
        let imageview = UIImageView()
        return imageview
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

         let tabBar = HMTabBar()
      
        setValue(tabBar, forKey: "tabBar")
        
        tabBar.CommonClickColure = {
            
            if HMusercount.shareuserCount.accessToken == nil
            {
                SVProgressHUD.showErrorWithStatus("没有登录,请登录")
            }
            
            let composeView = HMComposeView()
            
                composeView.show(self)
                        }
        // Do any additional setup after loading the view.
        addChildViewController(HMHomeTableViewController(), childtitle: "home", imagname: "tabbar_home")
        addChildViewController(HMMessageTableViewController(), childtitle: "消息", imagname: "tabbar_message_center")
        addChildViewController(HMDiscoverTableViewController(), childtitle: "发现", imagname: "tabbar_discover")
        addChildViewController(HMProfileTableViewController(), childtitle: "我", imagname: "tabbar_profile")
        
        
    }

    func dismiss(){
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    
  private  func addChildViewController(childController: UIViewController , childtitle : String , imagname : String) {
        
        
        childController.title = childtitle
        
        childController.tabBarItem.image = UIImage(named: imagname)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imagname)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        
        addChildViewController(HMNavigationViewController(rootViewController: childController))
    }
}
